package top.infopub.mgr.flow.web;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.flow.domain.TestBizDomain;
import top.infopub.mgr.flow.service.TestBizService;
import top.infopub.model.flow.TestBiz;
import top.infopub.security.util.SessionUserUtils;

import com.github.pagehelper.Page;


/**
 * 采购-工作流-测试   <br/>
 * 必须继承FlowGenericController
 * @author Awoke
 * @version 2019年11月5日
 * @see TestBizController
 * @since
 */
@Controller
@RequestMapping("/testBiz")
public class TestBizController extends GenericFlowController {

    @Autowired
    private TestBizService testBizService;

    /**
     * 列表页面
     * @return
     */
    @RequestMapping("/list")
    public String list(HttpServletRequest request) {
        return "awoke/testBiz";
    }

    /**
     * 跳转到审核页面/详情页面   > 注意：方法命名必须为：toDealOrDetail
     * @param request
     * @param id id=当前业务数据主键
     * @param id processDealWith=y时为审批表单 其他为详情数据
     * @return 
     * @see
     */
    @RequestMapping("/toDealOrDetail")
    public String toDealOrDetail(HttpServletRequest request, String id, String processDealWith) {
        TestBiz biz = testBizService.selectByPrimaryKey(id);
        request.setAttribute("modelDetail", biz);
        // 审批flag
        request.setAttribute("processDealWith", processDealWith);
        // 审批data
        processData(request, biz.getProcessId());

        return "awoke/testBiz-dealWithOrDetail";
    }

    /**
     * 列表数据--我发起的
     * @return
     */
    @RequestMapping("/queryDataByCondition")
    @ResponseBody
    public RspVo<TestBiz> queryDataByCondition(TestBiz paramVo, ParamPage paramPage) {
        paramVo.setAddBy(SessionUserUtils.getSessionUserId());
        Page<TestBiz> page = new Page<TestBiz>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = testBizService.queryPage(page, paramVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }
    
    /**
     * 列表数据--我审批的
     * @return
     */
    @RequestMapping("/queryDataByConditionMySee")
    @ResponseBody
    public RspVo<TestBizDomain> queryDataByConditionMySee(TestBiz paramVo, ParamPage paramPage) {
        paramVo.setAddBy(SessionUserUtils.getSessionUserId());
        Page<TestBizDomain> page = new Page<TestBizDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = testBizService.queryPageMySee(page, paramVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }

    /**
     * 新增
     * @return
     */
    @SuppressWarnings({"rawtypes"})
    @RequestMapping("/save")
    public @ResponseBody RspVo save(HttpServletRequest request, TestBiz model) {
        // 新增业务表单与工作审批流 
        testBizService.insertAndFlowProcess(model);
        return RspVo.getSuccessResponse();
    }

}
